package com.csu.mining.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.csu.mining.R;
import com.csu.mining.activity.PictureActivity;
import com.csu.mining.activity.VideoActivity;
import com.csu.mining.views.WEqualsHImageView;

import java.util.ArrayList;
import java.util.List;

public class MiningVideoAdapter extends RecyclerView.Adapter<MiningVideoAdapter.ViewHolder> {

    private int[] icons ={
            R.mipmap.way1,R.mipmap.way2,R.mipmap.way3,R.mipmap.way4,R.mipmap.way5,R.mipmap.way6,R.mipmap.way7,R.mipmap.way8
    };

    private int[] texts = {
            R.string.way1,R.string.way2,R.string.way3,R.string.way4,R.string.way5,R.string.way6,R.string.way7,R.string.way8
    };

    private List<Integer> listIcon=new ArrayList<Integer>();
    private List<Integer>listText=new ArrayList<Integer>();
    private Context mContext;
    public MiningVideoAdapter(Context context){
        mContext = context;
        for (int i=0;i<8;i++){
            listIcon.add(icons[i]);
            listText.add(texts[i]);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_grid_video,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.textView.setText(listText.get(position));
        holder.wEqualsHImageView.setImageResource(listIcon.get(position));
        holder.wEqualsHImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("order",position);
                intent.setClass(mContext, VideoActivity.class);
                mContext.startActivity(intent);
            }
        });
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("order",position);
                intent.setClass(mContext, VideoActivity.class);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 8;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        public WEqualsHImageView wEqualsHImageView;
        public TextView textView;
        public ImageView imageView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            wEqualsHImageView = (WEqualsHImageView) itemView.findViewById(R.id.video_img);
            textView = (TextView) itemView.findViewById(R.id.video_text);
            imageView=(ImageView)itemView.findViewById(R.id.video_start);
        }
    }
}
